#pragma once

#include <iostream>
#include <string>
#include "InetAddr.hpp"


//回调函数，根据不同的对象（监听套接字和普通套接字）执行不同的方法
using handler_t = std::function<std::string(std::string &)>;

class Reactor;

class Connection
{
public:
    Connection()
        :_owner(nullptr)
        ,_events(0)
    {}

    virtual void Recver() = 0;
    virtual void Sender() = 0;
    virtual void Excepter() = 0;
    virtual int GetSockFd() = 0;

    void SetEvent(const uint32_t &events)
    {
        _events = events;
    }

    uint32_t GetEvent()
    {
        return _events;
    }

    void SetOwner(Reactor* owner)
    {
        _owner = owner;
    }

    Reactor* GetOwner()
    {
        return _owner;
    }

    void RegisterHandler(handler_t handler)
    {
        _handler = handler;
    }

    ~Connection()
    {}

private:

    Reactor* _owner;

    //相关的事件
    uint32_t _events;

//派生类能访问
protected:  
    handler_t _handler;
};